#include <stdlib.h>
#include <conio.h>
#include <stdio.h>
#include <dos.h>
#include <io.h>
#include <fcntl.h>
#include <string.h>
#include <bios.h>
#include "rad.h"
#include "smack.h"
#include "dosext.h"
#include "svga.h"

#include "xenon.h"

FILE *dFile;

/**************************************************************************\
 write_trace - just for testing, write a trace file. -MCR
\**************************************************************************/

void write_trace(char *sentmsg)
{
	static int first_write=1;
	static FILE *fhndl;

	if (first_write) 
	{
		fhndl=fopen("xenon.trc","wt");
		first_write=0;
		fclose(fhndl);
	}
	fhndl=fopen("xenon.trc","a+");
	fwrite(sentmsg, 1, strlen(sentmsg)+1, fhndl);
	fclose(fhndl);
	return;
}

void openDebug()
{
	dFile = fopen("debug.txt","W");
	if (!dFile)
	{
		printf("Couldn't open Debug file");
	}

}
void closeDebug()
{
	fclose(dFile);
}

// -------------------------------------------------------------------
//	fatalerror()
//
//	A bad error handling function.
// -------------------------------------------------------------------

void fatalerror(char *m)
{
#ifdef DEBUGGING_ON
	_bios_timeofday(_TIME_GETCLOCK,&endTime);
#endif

	FWKeyboard_DestallDriver(); //Remove the keyboard driver
	SVGASetText();	// Back to text mode


#ifdef DEBUGGING_ON
	printf("Frames/Sec = %d\n",(frames*182) / ((endTime - startTime)*10));
#endif

	printf("%s\n",m);
	closeFirewall();
	exit(1);
}
